package com.example.boardroom.demo;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;

public class PowerReceiver extends BroadcastReceiver {

    private final String action_shutdown = Intent.ACTION_SHUTDOWN;
    private final String action_reboot = Intent.ACTION_REBOOT;

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        LogUtils.d("action = "+action);
        if (action_shutdown.equals(action)){
            //Power Off
            LogUtils.i("Power Off!");
            ToastUtils.showLong("Power Off!");
            YourCode();
        }else if (action_reboot.equals(action)){
            //Power reboot
            LogUtils.i("Power Reboot!");
            ToastUtils.showLong("Power Reboot!");
            YourCode();
        }
    }

    /**
     * your code
     * */
    private void YourCode(){
        // 你的逻辑
    }
}
